package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.PunishTypeEnum;
import org.jsola.hr.constant.RewardTypeEnum;
import org.jsola.hr.dto.EmpRewardPunishAddDTO;
import org.jsola.hr.dto.EmpRewardPunishUpdateDTO;
import org.jsola.hr.entity.EmpRewardPunishDO;
import org.jsola.hr.query.EmpRewardPunishQuery;
import org.jsola.hr.service.IEmpRewardPunishService;
import org.jsola.hr.vo.EmpRewardPunishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工奖惩记录
 *
 * @author zhr
 */
@Component
public class EmpRewardPunishTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpRewardPunishService empRewardPunishService;

    /**
     * 生成add测试数据
     * @return EmpRewardPunishAddDTO
     */
    public EmpRewardPunishAddDTO getEmpRewardPunishAddDTO(){
        EmpRewardPunishAddDTO empRewardPunishAddDTO = new EmpRewardPunishAddDTO();
        empRewardPunishAddDTO.setEmpId(getRandomValue("varchar",32));
        empRewardPunishAddDTO.setRewardPunish(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empRewardPunishAddDTO.setRewardType(RewardTypeEnum.ANNOUNCEMENT.getValue());
        empRewardPunishAddDTO.setPunishType(PunishTypeEnum.CRITICISM.getValue());
        empRewardPunishAddDTO.setHandleDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empRewardPunishAddDTO.setContent(getRandomValue("varchar",2000));
        empRewardPunishAddDTO.setAmount(SafeKit.getInteger(getRandomValue("int",11)));
        empRewardPunishAddDTO.setReason(getRandomValue("varchar",255));
        empRewardPunishAddDTO.setRemark(getRandomValue("varchar",255));
        empRewardPunishAddDTO.setCompanyId(getRandomValue("varchar",32));
        return empRewardPunishAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpRewardPunishUpdateDTO
     */
    public EmpRewardPunishUpdateDTO getEmpRewardPunishUpdateDTO(EmpRewardPunishVO empRewardPunishVO){
        return empRewardPunishService.selectDOById(empRewardPunishVO.getId(), SITE_ID).to(EmpRewardPunishUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpRewardPunishQuery
     */
    public EmpRewardPunishQuery getEmpRewardPunishQuery() {
        EmpRewardPunishQuery empRewardPunishQuery = new EmpRewardPunishQuery();
        List<EmpRewardPunishDO> empRewardPunishDOList = empRewardPunishService.list(new EmpRewardPunishDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empRewardPunishDOList)) {
            EmpRewardPunishDO empRewardPunishDO = empRewardPunishDOList.get(0);
            empRewardPunishQuery = empRewardPunishDO.to(EmpRewardPunishQuery.class);
            if (empRewardPunishDO.getHandleDate() != null) {
                empRewardPunishQuery.setHandleDateStart(DateKit.getBeforeDay(empRewardPunishDO.getHandleDate(),-1));
                empRewardPunishQuery.setHandleDateEnd(DateKit.getBeforeDay(empRewardPunishDO.getHandleDate(),1));
            }
        }
        return empRewardPunishQuery;
    }

    /**
     * 保存示例
     * @return EmpRewardPunishVO
     */
    public EmpRewardPunishVO saveEmpRewardPunishExample(){
        EmpRewardPunishAddDTO addDTO = this.getEmpRewardPunishAddDTO();
        EmpRewardPunishVO empRewardPunishVO = empRewardPunishService.save(addDTO,buildTokenUser());
        return empRewardPunishVO;
    }


}

